package initialize

import (
	"go-vue-element/global"
	"go.uber.org/zap"
	"gorm.io/gorm"
	"gorm.io/driver/mysql"
)

func Gorm() *gorm.DB {
	switch global.GVA_CONFIG.System.DbType {
	case "mysql":
		return GormMysql()
	default:
		return GormMysql()
	}
}
func GormMysql() *gorm.DB {
	m :=global.GVA_CONFIG.Mysql
	dsn := m.Username + ":"+m.Password+"@thp("+m.Path+")/"+ m.Dbname+"?"+m.Config
	mysqlConfig := mysql.Config{
		DSN:dsn,
		DefaultStringSize: 191,
		DisableDatetimePrecision: true,
		DontSupportRenameColumn: true,
		DontSupportRenameIndex: true,
		SkipInitializeWithVersion: false,
	}
	if db,err := gorm.Open(mysql.New(mysqlConfig),gormConfit(m.LogMode)); err != nil {
		global.GVA_LOG.Error("Mysql 启动异常",zap.Any("err",err))
	}
}